; extern double func(float x, float y);

global func

%define x [ebp + 8]
%define y [ebp + 12]

section .text

func:
	push ebp
	mov ebp, esp
	push esi
	push edi
	push ebx
	
	finit
	
	fldpi ; [pi] 
	fld x ; [x,pi]
	fadd st1, st0 ; [x, x+pi]
	fld st1 ; [x+pi,x,x+pi]
	fmulp st2 ; [x,(x+pi)*(x+pi)]
	fldpi ;  [pi,x,(x+pi)*(x+pi)]
	fsubrp st1, st0 ; [x-pi,(x+pi)*(x+pi)]
	fld st0 ; [x-pi,x-pi,(x+pi)*(x+pi)]
	fmulp ; [(x-pi)*(x-pi),(x+pi)*(x+pi)]
	fadd ; [(x-pi)*(x-pi)+(x+pi)*(x+pi)]
	fld1 ; [1|(x-pi)*(x-pi)+(x+pi)*(x+pi)]
	fld1 ; [1|1|(x-pi)*(x-pi)+(x+pi)*(x+pi)]
	faddp ; [2|(x-pi)*(x-pi)+(x+pi)*(x+pi)]
	fld ; [2|2|(x-pi)*(x-pi)+(x+pi)*(x+pi)]
	fadd ; [4|2|(x-pi)*(x-pi)+(x+pi)*(x+pi)]
	fld st0 ; [4|4|2|(x-pi)*(x-pi)+(x+pi)*(x+pi)]
	fadd st2 ; [6|4|2|(x-pi)*(x-pi)+(x+pi)*(x+pi)]
	fld1 ; [1|6|4|2|(x-pi)*(x-pi)+(x+pi)*(x+pi)]
	faddp ; [7|4|2|(x-pi)*(x-pi)+(x+pi)*(x+pi)]
	fmulp st3, st0 ; [4|2|7((x-pi)*(x-pi)+(x+pi)*(x+pi))]
	fdiv st2, st0 ; [4|2|7((x-pi)*(x-pi)+(x+pi)*(x+pi))/4]
	
	fld1 ; [1|4|2|7((x-pi)²+(x+pi)²)/4]
	fld st2 ; [7((x-pi)²+(x+pi)²)/4|1|4|2|7((x-pi)²+(x+pi)²)/4]
	fcos ; [cos(7((x-pi)²+(x+pi)²)/4)|1|4|2|7((x-pi)²+(x+pi)²)/4]
	
	fyl2x ; st0 = 1 * log2(cos(7 * (x - Pi)^2 + (x + Pi)^2 /4)), st1 = 1, st2 = 4, st3 = 2, st4 = 7 * (x - Pi)^2 + (x + Pi)^2 /4
	fldl2e ; st0 = 1 * log2(cos(7 * (x - Pi)^2 + (x + Pi)^2 /4)), st1 = 1, st2 = 4, st3 = 2, st4 = 7 * (x - Pi)^2 + (x + Pi)^2 /4
	fadd st0 ; st0 = 2 log2(cos(7 * (x - Pi)^2 + (x + Pi)^2 /4)), st1 = 1, st2 = 4, st3 = 2, st4 = 7 * (x - Pi)^2 + (x + Pi)^2 /4
	fadd st0, st1 ; st0 = 2 log2(cos(7 * (x - Pi)^2 + (x + Pi)^2 /4)) + 1, st1 = 1, st2 = 4, st3 = 2, st4 = 7 * (x - Pi)^2 + (x + Pi)^2 /4
	fldl2t ; st0 = log2(10), st1 = 2 log2(cos(7 * (x - Pi)^2 + (x + Pi)^2 /4)) + 1, st2 = 1, st3 = 4, st4 = 2, st5 = 7 * (x - Pi)^2 + (x + Pi)^2 /4
	fsubr st0, st1 ; st0 = 2 log2(cos(7 * (x - Pi)^2 + (x + Pi)^2 /4)) + 1 - log2(10), st1 = 2 log2(cos(7 * (x - Pi)^2 + (x + Pi)^2 /4)) + 1, st2 = 1, st3 = 4, st4 = 2, st5 = 7 * (x - Pi)^2 + (x + Pi)^2 /4
	f2xm1 ; 
	fadd st0, st3 ; 

	
fin:
	pop ebx
	pop edi
	pop esi
	pop ebp
	ret
